﻿#include <iostream>
#include <vector>
using namespace std;


/*添加到二维数组*/
class Graph {
private:
    int numVertices;
    vector<vector<int>> adjMatrix;
    vector<int> adjMatrix2;
public:
    // 构造函数，初始化图的大小和邻接矩阵
    Graph(int n) : numVertices(n), adjMatrix(n, vector<int>(n, 0)), adjMatrix2(n,0){}

    // 添加边（无向图）
    void addEdgeUndirected(int i, int j) {
        adjMatrix2[i] = 2;
        adjMatrix[i][j] = 1;
        adjMatrix[j][i] = 1; // 因为是无向图，矩阵是对称的
       
    }

    // 添加边（有向图）
    void addEdgeDirected(int from, int to) {
        adjMatrix[from][to] = 1;
    }

    // 添加带权重的边（有向）
    void addEdgeDirected(int from, int to, int weight) {
        adjMatrix[from][to] = weight;
    }

    // 打印邻接矩阵
    void printMatrix() {
        for (int i = 0; i < numVertices; i++) {
            for (int j = 0; j < numVertices; j++) {
                cout << adjMatrix[i][j] << " ";
            }
            cout << endl;
        }
    }
};

int main() {
    Graph g(4); // 创建一个有 4 个顶点的图

   /* g.addEdgeUndirected(0, 1);
    g.addEdgeUndirected(0, 2);
    g.addEdgeUndirected(1, 2);
    g.addEdgeUndirected(2, 3);*/
    g.addEdgeDirected(0, 1);
    g.addEdgeDirected(0, 2);
    g.addEdgeDirected(1, 2);
    g.addEdgeDirected(2, 3);


    
    cout << "Undirected Graph Adjacency Matrix:" << endl;
    g.printMatrix();

    return 0;
}